<template>
	<view>
		<view style="z-index: 999; top: 0; background-color: rgba(255,255,255,0);" class="cu-custom position-fixed w-100 text-white" :style="[{height:CustomBar + 'px', maxHeight:CustomBar + 'px'}]">
			<!-- <view class="logo-img flex justify-end p-2">
				<image mode="heightFix" class="logo rounded-circle" src="../static/logo.png"></image>
			</view> -->
			<view class="cu-bar " :style="style" :class="[bgImage!=''?'none-bg text-blue bg-img':'',bgColor]">
				<view class="d-flex justify-content-start align-center">
					<view class="action" @tap="BackPage" v-if="isBack">
						<text class="cuIcon-back text-blue"></text>
						<slot name="backText"></slot>
					</view>
					<view v-if="showLocation" style="background-color: rgba(255,255,255,0);" class="p-2 ">
						<view class="d-flex justify-content-start align-items-center" @click="changeCity">
							<image class="location mr-1" mode="aspectFill" src="../static/locationpoint.png" ></image>
							
							<text v-if="location">
								<text v-if="location.area">{{location.area.criname}}</text>
								<text v-else-if="location.city">{{location.city.criname}}</text>
								<text v-else-if="location.provice">{{location.provice.criname}}</text>
							</text>
							<text v-else>
								未选择
							</text>
							<image class="down ml-1" mode="aspectFill" src="../static/down.png" ></image>
						</view>
					</view>
				</view>
				<view class="content text-blue" :style="[{top:StatusBar + 'px'}]">
					<slot name="content"></slot>
				</view>
				<slot name="right"></slot>
			</view>
			
		</view>
	</view>
</template>

<script>
	export default {
		created: function() {
			
		},
		data() {
			return {
				StatusBar: this.StatusBar,
				CustomBar: this.CustomBar,
				cityName: "",
			};
		},
		name: 'cu-custom',
		computed: {
			style: function() {
				var StatusBar= this.StatusBar;
				var CustomBar= this.CustomBar;
				var bgImage = this.bgImage;
				var style = `height:${CustomBar}px;padding-top:${StatusBar}px;`;
				if (this.bgImage) {
					style = `${style}background-image:url(${bgImage});`;
				}
				return style
			},
			location: function() {
				return this.store.state.location;
			}
		},
		props: {
			bgColor: {
				type: String,
				default: ''
			},
			isBack: {
				type: [Boolean, String],
				default: false
			},
			showLocation: {
				type: [Boolean, String],
				default: true
			},
			bgImage: {
				type: String,
				default: ''
			},
		},
		
		methods: {
			BackPage() {
				uni.navigateBack({
					delta: 1
				});
			},
			changeCity: function() {
				uni.navigateTo({
					url: "/pages/location?key=1"
				});
			}
		}
	}
</script>

<style>
	.logo-img {
		position: absolute;
		top: 0;
		width: 100%;
		height: 100%;
	}
	
	.logo-img .logo {
		height: 100%;
	}
	
	.location {
		width: 27rpx;
		height: 33rpx;
	}
	
	.down {
		width: 12rpx;
		height: 12rpx;
	}
</style>
